package com.etoak.config;

import com.etoak.common.core.properties.ImageProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.config.ResourceHandlerRegistry;
import org.springframework.web.reactive.config.WebFluxConfigurer;

@Configuration
public class WebFluxConfiguration implements WebFluxConfigurer {
    @Autowired
    ImageProperties imageProperties;

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
    String mapping=imageProperties.getPrefix().endsWith("/")?
                imageProperties.getPrefix()+"**":
                imageProperties.getPrefix()+"/**";
    String location =imageProperties.getLocation().endsWith("/")?
            imageProperties.getLocation():
            imageProperties.getLocation()+"/";

    registry.addResourceHandler(mapping).addResourceLocations("file:"+location);
    }
}
